package com.myapi.ModelPoker;

import java.io.Serializable;
import java.util.ArrayList;

import com.google.gwt.user.client.rpc.IsSerializable;
import com.myapi.client.DAO.CardDAO;

/**
 * Card
 * @author Realease by Yoan Oliver
 *
 */
public class Card implements Comparable,IsSerializable {
	
	   private static final long serialVersionUID = 3556718687164361458L;
	   /**
		 * @gwt.typeArgs<com.myapi.client.Card>
		 */
	   
	   
	public static final String SPADE = "Spade";
	public static final String HEART = "Heart";
	public static final String CLUB = "Club";
	public static final String DIAMOND = "Diamond";
	
	
	private int value;  //2 = 2, Jack = 11, Queen = 12, King = 13, Ace = 14
	private String suit;
	public Card(){
		
	}
	
	/**
	 * Constuctor of Card
	 * @param value Value of the card
	 * @param suit Color
	 */
	public Card(int value, String suit) {
		this.value = value;
		this.suit = suit;		
	}
	
	public String getSuit() {
		return suit;
	}
	
	public int getValue() {
		return value;
	}
	/**
	 * Cards are arranged in a sorted Collection from highest card first down to lowest card
	 * Order is imposed on suit too, so that duplicates cannot be inserted. The ordering on suit is not used in the gameplay however
	*/
	public int compareTo(Object o) {
		assert o instanceof Card;
		Card card = (Card) o;
		int cValue = card.getValue();
		String cSuit = card.getSuit();
		if(getValue() < cValue) {
			return 1;
		} else if(getValue() > cValue) {
			return -1;
		} else if(getSuit().equals(cSuit)) {
			return 0;
		} else {  //Order: Spade, Heart, Club, Diamond
			if(getSuit().equals(DIAMOND)) {
				return 1;
			} else if(getSuit().equals(SPADE)) {
				return -1;
			} else if(getSuit().equals(HEART) && !cSuit.equals(SPADE)) {
				return -1;
			} else if(cSuit.equals(SPADE)) {
				return 1;
			} else if(getSuit().equals(CLUB) && !cSuit.equals(DIAMOND)) {
				return 1;
			} else if(cSuit.equals(DIAMOND)) {
				return -1;
			}
			return 0;
		}
	}

	public CardDAO getInfo() {
		CardDAO cardDAO=new CardDAO();
		cardDAO.setSuit(this.getSuit());
		cardDAO.setValue(this.getValue());
		return cardDAO;
	}

	
}
